$(function () {
    //初始化加载
    initJfmx();
});

function initJfmx() {
    var options = getJfmxGridOption();
    var queryParam = {

    }
    $('#jfmx_grid').datagrid(options);
}

function getJfmxGridOption() {
    var options = {
        url: $.webPath() + "/xsgl/jfmx/jfmxList",
        toolbar: "#jfmx-toolbar",
        fitColumns: false,
        singleSelect: true,
        pagination: true,
        fit: true,
        pageNumber: 1,
        rownumbers: true,
        onSelect: function (rowIndex, rowData) {

        }

    };
    var columns = {columns: [
        [
            {field: 'xsxt_xsdh', title: '销售系统子项号', align: 'center', width: 150},
            {field: 'bm', title: '关联收款', align: 'center', width: 257},
            {field: 'name', title: '品名', align: 'center', width: 80},
            {field: 'ggxh', title: '规格型号', align: 'center', width: 100},
            {field: 'cz', title: '材质', align: 'center', width: 80},
            {field: 'zl', title: '重量', align: 'center', width: 100, formatter: function (value) {
                var sl = formatSl(value, ",");
                return sl;
            }},
            {field: 'hsj', title: '含税价', align: 'center', width: 100, formatter: function (value) {
                var sl = formatJe2(value, ",");
                return sl;
            }},
            {field: 'sjjsj', title: '实际结算价', align: 'center', width: 100, formatter: function (value) {
                var sl = formatJe2(value, ",");
                return sl;
            }},
            {field: 'ghje', title: '赎货金额', align: 'center', width: 100, formatter: function (value) {
                var sl = formatJe2(value, ",");
                return sl;
            }},
            {field: 'zjfpje', title: '资金分配金额', align: 'center', width: 100, formatter: function (value) {
                var sl = formatJe2(value, ",");
                return sl;
            }},
            {field: 'khfksj', title: '赎货时间', align: 'center', width: 100},
            {field: 'tzfksj', title: '投资付款时间', align: 'center', width: 100},
            {field: 'sjzyts', title: '实际占用天数', align: 'center', width: 100},
            {field: 'jszyts', title: '计算占用天数', align: 'center', width: 100},
            {field: 'dlfje', title: '代理费金额', align: 'center', width: 100, formatter: function (value) {
                var sl = formatJe2(value, ",");
                return sl;
            }},
            {field: 'txje', title: '贴息金额', align: 'center', width: 100, formatter: function (value) {
                var sl = formatJe2(value, ",");
                return sl;
            }},
            {field: 'shsj', title: '赎货时间', width: 100, align: 'center'},
            {field: 'sfjs', title: '是否结算', align: 'center', width: 50, formatter: function (value) {
                if (value == 1)
                    return "已结算";
                if (value == 0)
                    return "未结算";
            }}
        ]
    ]}
    options = $.extend(options, columns);
    return options;
}

function jfmx_tx() {
    $.messager.confirm('确认', '是否计算所有未计算的贴息', function (r) {
        if (r) {
            $.ajax({
                url: $.webPath() + "/xsgl/jfmx/jfmx_tx",
                dataType: 'json',
                type: 'POST',
                beforeSend: function () {
                    $("#layout_jfmx").mask();
                },
                success: function (data) {
                    $("#layout_jfmx").mask("hide");
                    if (data.statusCode == 200) {
                        $('#jfmx_grid').datagrid('reload');
                        $.messager.show({
                            title: '提示',
                            msg: data.message,
                            timeout: 3000,
                            showType: 'slide'
                        });
                    } else {
                        $.messager.alert("提示", data.message, "error");
                    }
                }
            });
        }
    });
}
